package com.hbm.util;

import org.hibernate.*;

public class HibernateTemplate {

	public static final Object execute(HibernateCallback hc) {
		Session ses = null;
		Transaction tx = null;
		Object obj = null;
		try {
			ses = HibernateUtil.getSession();
			tx = ses.beginTransaction();
			obj = hc.doHibernate(ses);
			tx.commit();
		} catch (HibernateException e) {
			if (tx != null) {
				tx.rollback();
			}
			e.printStackTrace();
		} finally {
			HibernateUtil.close(ses);
		}
		return obj;
	}
}
